Method and apparatus for distinguishing reachable objects and non-reachable objects in an object-based application

ABSTRACT

The invention is directed to a method for distinguishing reachable objects and non-reachable objects in an object-based application in a system with a volatile memory and a non-volatile memory. The object-based application operates in the non-volatile memory on the objects, whereof at least one is a root object. Each root object is processed by writing for each object that is reachable from the root object, a positive reachability information into the volatile memory and marking those objects in the non-volatile memory as reusable memory, for which no positive reachability information is present in the volatile memory.

[0001] The invention concerns a method for identification and collection of memory sections that contain information not needed anymore, commonly referred to as garbage. This approach is well suited for use in systems with memory of limited size, such as integrated-circuit cards, e.g. smartcards.

TECHNICAL FIELD AND BACKGROUND OF THE INVENTION

[0002] Object-based application programs, e.g. written in Java, C++, or the like, usually operate on directed graphs. These graphs comprise root objects and regular objects which are interconnected by means of pointers. During the execution of an object-based application program the graph dynamically changes as objects and/or pointers are added, modified or removed.

[0003] Object-based execution environments often support the application developer in one of the most tedious and error-prone tasks in programming, namely memory-handling. In many systems, objects are only allocated by the application program, but never explicitly de-allocated. In these systems it is the task of a so-called garbage collector to determine which objects are no longer needed and to give the memory space occupied by those objects free for new objects. The garbage collector frees-up the respective memory and returns it to the heap of unused and hence usable memory. A garbage collector is designed to, every once in a while, clean up wasted memory. In addition, the garbage collector might be used to compact memory by eliminating the gaps created by fragmentation.

[0004] Cleaning up the garbage in memory is usually done in two steps, referred to as marking and sweeping. A known SUN Java garbage collector also uses the mark-and-sweep approach according to which every root object in the system is marked initially. Then one follows all the object references inside those objects to other objects not yet marked, and so on, recursively. Finally, when there are no more references to follow, all unmarked objects are deleted.

[0005] Current garbage collection schemes are not well suited for use in resource-constrained systems because these garbage collection schemes require more volatile memory than usually available in these kind of systems.

[0006] An integrated-circuit card, more widely known as smartcard, is one example of such a resource-constrained system. Other examples are mobile and/or hand held devices, such as cellular phones, pagers, personal digital assistants, personal area network devices, and so forth.

[0007] In the following, it will be focused mainly on ICCs and smartcards in particular. The smartcard concept began in Europe prior to 1985, and is today being used in telephone systems, toll roads, game parlors, and personal computers, just to mention some applications.

[0008] In the following, the term integrated-circuit card, short ICC, will be used, because ISO uses the term to encompass all those devices where an integrated-circuit is contained within a card-size piece of plastic, or the like. Typical ICCs comprise a microprocessor (central processing unit, CPU), a read-only memory (ROM), a volatile random-access memory (RAM), and some type of the non-volatile, programmable memory, such as an EEPROM (electrically erasable programmable read-only memory). In addition, an ICC usually comprises some kind of a bus (such as a serial bus) and I/O ports for interconnection to a card terminal.

[0009] The contents of the ROM-type of memory is fixed and can not be changed once manufactured by the semiconductor company. This is a low-cost memory that occupies minimum space on the substrate. It is a disadvantage of a ROM that it cannot be changed and that it takes several months to be produced. As opposed to this, an EEPROM is erasable by the user and can be rewritten many times. ROMs and EEPROMs are the non-volatile. In other words, when the power is removed they still retain their contents.

[0010] A RAM is a volatile memory and as soon as the power is removed the data content is lost. A RAM, on the other hand, has the advantage that it is much faster writable to and readable from than ROMs and EEPROMs. A RAM is however more expensive in terms of die size. Usually, the RAM is relatively small. A RAM is typically not used for operations involving data that has to be kept permanent and consistent. Thereofor typically the non-volatile memory is used. Unfortunately, using the non-volatile memory for any and all operations has a couple of serious drawbacks. One is the extreme performance penalty that has to be paid as every memory write access is roughly 500 to thousand times slower when using an EEPROM instead of a RAM. An even more serious problem is the limitation on the amount of guaranteed write cycles, which is only 100000 times for an EEPROM.

[0011] In a resource-constrained system the volatile memory is usually significantly limited in size, and the computing power is as well significantly limited, e.g. because a small CPU is employed. Such resource-constrained systems usually also operate at low clock cycle rates.

OBJECT AND ADVANTAGES OF THE INVENTION

[0012] It is an object of the present invention to provide a garbage collection scheme which is well suited for use in resource-constrained systems.

[0013] It is a further object to provide a garbage collection scheme which has a reduced number of write-steps in the persistent memory.

SUMMARY OF THE INVENTION

[0014] The invention is directed to a method for distinguishing reachable objects and non-reachable objects in an object-based application in a system with a volatile memory and a non-volatile memory. The object-based application operates in the non-volatile memory on the objects, whereof at least one is a root object

[0015] Each root object is processed by writing for each object that is reachable from the root object, a positive reachability information into the volatile memory and marking those objects in the non-volatile memory as reusable memory, for which no positive reachability information is present in the volatile memory.

[0016] The writing of the reachability information into the volatile memory has the advantage that it is faster and cheaper. Since lifetime of the persistent memory is limited much more than the lifetime of a volatile memory, the lifetime is lengthened with each write-step that is performed in the volatile memory instead of the persistent memory.

DESCRIPTION OF THE DRAWINGS

[0017] Examples of the invention are depicted in the drawings and described in detail below by way of example. It is shown in

[0018]FIG. 1 a schematic view of an integrated-circuit card (ICC) with its main units,

[0019]FIG. 2 an example for an arrangement of objects in an EEPROM with a corresponding reachability pattern in a RAM.

[0020] All the figures are for sake of clarity not shown in real dimensions, nor are the relations between the dimensions shown in a realistic scale.

DETAILED DESCRIPTION OF THE INVENTION

[0021] In the following, the various exemplary embodiments of the invention are described.

[0022] In FIG. 1 is depicted an ICC 10 which carries a microprocessor CPU 12, a first non-volatile memory, ROM 11, a second non-volatile memory, EEPROM 13, and a volatile memory, RAM 14, like most conventional ICCs.

[0023] The ICC 10 furthermore comprises an internal bus 19, connected to the CPU 12 and to the memories 11, 13, 14, allowing exchange of information and signaling between the ICC's components. The ICC 10 is a contact card with I/O ports, which are the interface for connecting to corresponding means of a card terminal. As indicated in FIG. 1, power is supplied via a ground port 17 (GND) and a positive voltage port 18 (VCC). Both ports 17, 18 are connected to the CPU 12 and the memories 11, 13, 14. In the ROM 11, the code of programs or an operating system is storable.

[0024] The invention concerns a garbage collection (GC) technique for use in systems with constrained resources. The following assumptions are made about the system executing the garbage collection technique:

[0025] There are two types of memory: the volatile memory 14 and the persistent i.e. non-volatile memory 13. The volatile memory 14 has following characteristics:

[0026] The available size of this volatile memory 14 is limited either because of the available physical memory or because only a limited amount of memory can be dedicated to the garbage collection task.

[0027] Reading from and writing to the volatile memory 14 is fast compared to read/write access to the non-volatile memory 13.

[0028] The non-volatile memory 13 has the following characteristics:

[0029] The non-volatile memory 13 holds a multiplicity of objects.

[0030] Writing to the non-volatile memory 13 is time-consuming compared to writing to the volatile memory 14.

[0031] The objects residing in the non-volatile memory 13 can be enumerated.

[0032] Each object comprises an object header 23 and an object payload 22. Object header 23 and object payload 22 need not be located in consecutive memory cells.

[0033] The object payload 22 is freely usable for any code while the object header 23 is dedicated to system tasks. During garbage collection some information is stored in the object header 23 of each object. The amount of information contributed by garbage collection to the object header 23 should be small since the object header 23 is overhead.

[0034] Typical examples for the volatile memory 14 are RAM or cache memory, and the non-volatile memory 13 could be an EEPROM, FlashRAM, or disk storage.

[0035] In an object-based environment, the non-volatile memory 13 typically contains a multiplicity of objects. Each object can be enumerated and accessed via a pointer, i.e. an address which allows to find the object. A pointer in this context is some datum which contains an object address that is said to refer to some object. Each object contains a possibly empty set of pointers to objects and a possibly empty set of other information not referring to any objects. Given some object A, it is possible to enumerate all pointers stored in this object A which refer to other objects. The objects are located in the non-volatile memory 13 and their pointers constitute a directed graph DG, as explained in more detail in relation to FIG. 2.

[0036] The purpose of garbage collection is to identify those objects that are no longer referenced by other still used objects. The memory space occupied by those identified obsolete objects can then be reused for other objects.

[0037] Some initial objects, also referred to as root objects, are known to be essential and thus not subject to garbage collection. This set of root objects is system-dependent and does not affect the present garbage identification- and collection scheme. This set of objects is referred to as the initial rootset IR.

[0038] Per definition, the objects reachable within the directed graph DG in the non-volatile memory 13 from the objects in the initial rootset IR are not deemed to be garbage. All objects which are not reachable from any object in the initial rootset IR are deemed to be garbage. Their memory space comprising object header and object payload, can be reclaimed by the system for new use, i.e. the space in the memory occupied by the object can be overwritten with other objects.

[0039] It is assumed a path TO in the directed graph DG starting from a current root object T and ending at some object O. The object T is said to be the first object in TO and the object O is said to be the last object thereof. The garbage identification- and collection scheme aims at making a distinction between reachable and non-reachable objects. For this purpose, the following states are maintained in the volatile memory 14:

[0040] the number Z of unprocessed root objects, this number being provided e.g. by means of a counter,

[0041] the current root object T,

[0042] a description of the path TO.

[0043] In the non-volatile memory 13 each object header might have two bits dedicated to the garbage collection scheme:

[0044] A VF bit (visited flag bit): this bit indicates whether an object has been visited during the current execution of the garbage collection algorithm. The definition of 0 and 1, meaning visited or not, can be altered to avoid the resetting of all object's VF bits after a garbage collection run. The VF bit is herein referred to as reachability information since it indicates, once the identification process has been performed, whether an object is tied via a pointer and mybe other objects and pointers to one of the root objects and hence can be reached therefrom or whether this object is decoupled from any root object and can not be reached. Here positive reachability information means VF=1 and negative reachability information means VF=0.

[0045] A RF bit (root flag bit): This flag indicates if an object is a root object which has not yet been processed. “RF set” or “RF=1” means the object is marked as root object and still needs to be processed.

[0046] In the following, the steps of an exemplary implementation of the garbage collection method are given. It essentially comprises a marking process followed by a memory-reclaiming process. Each object has an identifier, i.e. a name, number or the like.

[0047] 1. All initial root objects in the initial rootset IR are marked unprocessed, i.e. with RF=1. The other objects have their RF flag reset to 0. The number Z of unprocessed root objects is set to the number of marked root objects.

[0048] 2. If the number Z of unprocessed root objects is zero, then all objects in the non-volatile memory 13 are enumerated and the memory of those with the VF flag not set is reclaimed. This is the sweeping process or reclaiming process. Then the garbage collection process is terminated.

[0049] 3. Otherwise the objects in the non-volatile memory 13 are enumerated and the first object which has its RF flag set is identified. This root object is referred to as first path object T for the path TO. It is also referred to as the current object C.

[0050] 4. Then all pointers in the current object C are enumerated. If all pointers in the current object C have been processed in this step 4, the process continues with step 5. Otherwise, for each pointer referring to some object O which has its VF flag not set the following steps a to c are performed:

[0051] a. The VF flag is set.

[0052] b. If the volatile memory 14 is not exhausted, i.e. has enough space for adding the identifier of an object to the path TO, then the identifier of the current object C is added to the path TO and the referred object O is referred to as the new current object C. Step 4 is continued with the next referred object which has its VF flag not set.

[0053] c. Otherwise, the RF flag of the referred object O is set and the number Z of unprocessed root objects is incremented. Step 4 is continued with the next pointer.

[0054] 5. If the path TO is empty, the RF flag of the first path object T is reset and its VF flag is set. The number Z of unprocessed root objects is decremented. Then the process continues with step 2.

[0055] 6. Otherwise, the identifier of the last object of the path TO is removed from this path TO. This removed object is defined as the new current object C. Then the process continues with step 4.

[0056] The garbage collection algorithm needs to have at least space to store paths of length 2 in the volatile memory 14. The step 4b handles all cases when the path TO is about to get longer than it is allowed to be. In such a case, the full path TO could not be stored and information about the beginning or the end of the path TO could get lost which would make the process faulty.

[0057] The longer the path TO can be, the faster is the execution of the garbage collection method, since less independent paths TO have to be processed. The state can further be minimized by choosing specific representations of the path TO in the volatile memory 14. A faster, but space-consuming representation would be a sequence of pointers referring to the objects of the path TO. As the set of possible pointers is usually bigger than the average number of pointers contained in objects, the following optimization can be applied:

[0058] Let r be the number of pointers in object O. r′ is the minimum number which is bigger or equal to r and which is a power of two. Only log2(r′) bits are needed to represent a path element from 0 to one of its referred objects Q Assuming that the pointer to some object Q is the i-th pointer in the object O then only the least log2(r) bits of the number i are stored in the path TO. The computation of the last object in some path TO is done by starting at its root T and following the i-th pointers from one object to the other object.

[0059] Since, as explained above, the writing to the persistent memory 13 is slow and expensive, the flag VF is better kept in the volatile memory 14. Therefor for each object in the persistent memory a marking information is created which contains the VF flag.

[0060] The marking information and the objects are preferably aligned with each other, i.e. the order of the pieces of marking information is the same as the order of the corresponding objects. In the following it is assumed that the marking information consists of a single bit, referred to as the VF bit.

[0061] 1. Initially in the volatile memory 14 the space necessary for containing all VF bits of all possible objects is reserved and cleared, i.e. set to 0.

[0062] 2. The above described marking process (steps 1, 3, 4, 5, 6) is performed, whereby the writing of the VF flags is not performed in the persistent memory 13 but they are written in form of the VF bits in the volatile memory 14. In the persistent memory 13 no writing activity related to the marking takes place.

[0063] In FIG. 2 an exemplary arrangement comprising several objects A, B, C, D, E, F, G in the persistent memory 13 is depicted. Each of these objects A, B, C, D, E, F, G is positioned at a respective object address aA, aB, aC, aD, aE, aF, aG. For example the object A has as its start address in the persistent memory 13 the object address aA. The objects A, B, C, D, E, F, G are partially connected via the directed graph DG which here comprises a pointer from the object A to the object E and another pointer to the object B which again has a pointer to the object C. The objects D, F, G are not referred to by pointers. Only the object A is here an initial root object. The volatile memory 14 comprises for each object A, B, C, D, E, F, G the corresponding VF bits A′, B′, C′, D′, E′, F′, G′ which are located in this volatile memory 14 at respective marking information addresses aA′, aB′, aC′, aD′,aE′, aF′, aG′.

[0064] There is a fixed relationship between the object address aA, aB, aC, aD, aE, aF, aG and the marking information addresses aA′, aB′, aC′, aD′, aE′, aF′, aG′. This relationship is such that with an algorithm for each object A, B, C, D, E, F, G the corresponding VF bits A′, B′, C′, D′, E′, F′, G′ can be addressed. The relationship can be of the following kind:

[0065] All objects in the persistent memory 13 are aligned on a predetermined boundary thereof, e.g. an address that is a multiple of a number n. This number n then shall fulfill e.g. the equation

[0066] n=(size of the persistent memory)/8*(size of the volatile memory)

[0067] This fixed relation allows quick and uncomplicated access to the corresponding VF bits. Other relations are suited as well, as long as they are unambiguous in both directions.

[0068] The writing of the VF bit for a specific object O with its address aO is done by writing to aO/n. After performing the above described process, in the volatile memory 14 the bit pattern of all VF bits represents the accessability, resp. reachability of the objects A, B, C, D, E, F, G in the persistent memory 13.

[0069] The step 2 which contains the sweeping part, i.e. reclaiming, of the garbage collection process, is performed in that all objects whose VF bit is 0 are defined as garbage and their memory space is defined as free. This is typically done by changing the object header 23. In the case an object is present, the object header 23 contains a use information 24 which tells that the space following is occupied by an object A, B, C, D, E, F, G. The object header 23 gives also the size of the object A, B, C, D, E, F, G. Deleting an object A, B, C, D, E, F, G can hence simply be done by overwriting the use information 24 to then tell that no object A, B, C, D, E, F, G follows. Since writing is expensive in the persistent memory 13, it makes only little sense to overwrite the whole object A, B, C, D, E, F, G for deleting it. Making the system no longer interpret the memory space as object, has the same effect as deleting it, as regards memory occupation. For localizing the object A, B, C, D, E, F, G in the persistent memory 13, the fixed relation between the object address aA, aB, aC, aD, aE, aF, aG and the marking-information address aA′, aB′, aC′, aD′, aE′, aF′, aG′ is again of use. Finding e.g. a VF=0 at the marking-information address aE′, leads directly to the corresponding object address aE where the sweeping part therefor can be performed.

[0070] It is also of advantage to locate the RF flags in the volatile memory 14. Also the path TO should be located in the volatile memory 14 and even the number Z can be maintained there. Thereby the minimum of the writing operations is performed in the persistent memory 13, whereby the lifetime of the persistent memory 13 is lengthened and operation speed for the garbage collection process is increased.

[0071] For certain applications, especially on the smartcard area, it is important to to guarantee consistency of data even during power failure. This means that in case of sudden power loss and later restart, it shall be impossible that the state of the smartcard and its stored code is incorrect. This could for example occur, when a root object is marked as being processed before the processing of its referred objects is done and during this processing the power is lost. If the RF flag survives the power loss, but the porcess does not start at the same position, some objects could remain unprocessed and be regarded as garbage although they are valid and reachable objects. With the described scheme that uses the volatile memory 14 for the VF flags and possibly also the other information which is used during the garbage collection process, consistency is also guaranteed. The volatile memory 14 is emptied on power loss and hence no state from a previous garbage collection process run can influence a new run.

[0072] The present invention allows conventional. ICCs and other systems, and in particular resource-constrained systems, to be modified by simply integrating the essential components either as hardware, as software, or as a combination of hardware and software. The invention enables a variety of applications that identify those objects F, G, D which are not needed anymore. Once these objects F, G, D have been successfully identified, one can delete them to free-up the respective memory sections. Instead of deleting these objects F, G, D, one can add their pointers to a queue. The pointers in this queue then point to the sections in the persistent memory 13 which can be overwritten. Each time when memory space is required for storing an object, a pointer might be removed from the queue. Then the corresponding object is written into the memory section identified by the respective pointer.

[0073] One can also compact the persistent memory 13 once all non-reachable objects F, G, D have been identified. This is of advantage in the case the persistent memory 13 was fragmented.

[0074] In the described embodiment, the CPU 12 is the processor 12 including a counter for counting the number Z of root objects that were not yet processed and the reclaimer means for reclaiming those sections of the volatile memory 14 which contain the objects A, B, C, D, E, F, G which have no positive reachability information VF. It also comprises a defragmenter for the compacting step.

[0075] It is obvious for the person skilled in the art that the present invention can be realized in hardware, software, or a combination of these. Also, it can be implemented in a centralized fashion on one single computer system, or in a distributed fashion where different elements are spread across several interconnected computers or computer systems, whereby any kind of a computer system—or other apparatus adapted for carrying out the methods described herein—is suited. A typical combination of hardware and software could be a general purpose computer system with a computer program that, when being loaded and executed, controls the computer system such that it carries out the methods described herein. The present invention can also be embedded in a computer program product, which comprises all the features enabling the implementation of the methods described herein, and which when loaded in a computer system—is able to carry out these methods.

[0076] Computer program means or computer program in the present context mean any expression, in any language, code or notation, of a set of instructions intended to cause a system having an information processing capability to perform a particular function either directly or after either or both of the following a) conversion to another language, code or notation; b) reproduction in a different material form.

[0077] Any disclosed embodiment may be combined with one or several of the other embodiments shown and/or described. This is also possible for one or more features of the embodiments.

[0078] It is obvious that a person skilled in the art can modify the shown arrangements in many ways without departing from the gist of the invention which is encompassed by the subsequent claims.

[0079] The present invention can be used in any kind of system in which an object-based application is executed. The invention is in particular suited for use in resource-constrained systems.

[0080] Typical resource-constrained systems are:

[0081] integrated-circuit card (ICC) (e.g. smart cards);

[0082] telephones;

[0083] set-top-boxes;

[0084] embedded controllers;

[0085] hand held devices;

[0086] portable computers;

[0087] personal area network (PAN) devices, etc. 

1. Method for distinguishing reachable objects (A, B, C, E) and non-reachable objects (D, F, G) in an object-based application in a system with a volatile memory (14) and a non-volatile memory (13), said object-based application operating in said non-volatile memory (13) on said objects (A, B, C, D, E, F, G) , whereof at least one is a root object (A), said method comprising the steps: processing each root object (A) by writing for each object (A, B, C, D, E, F, G) that is reachable from said root object (A), a positive reachability information (VF) into said volatile memory (14), marking those objects (A, B, C, D, E, F, G) in said non-volatile memory (13) as reusable memory, for which no positive reachability information (VF) is present in said volatile memory (14).
 2. The method of claim 1, whereby a counter is employed to count the number (Z) of root objects (A) that have not yet been processed, said counter being preferably maintained in said volatile memory (14).
 3. The method of claim 1 or 2, operating on said objects (A, B, C, D, E, F, G) having an object payload (22) and an object header (23), whereby said object payload (22) may comprise pointers to others of the objects (A, B, C, D, E, F, G).
 4. The method of one of claims 1 to 3, whereby a flag (RF) is maintained which indicates that an object (A, B, C, D, E, F, G) is a root object (A), preferably in said volatile memory (14).
 5. The method of one of claims 1 to 4, whereby all root objects (A) are initialized to indicate that they have not yet been processed, this initialization being done prior to the execution of the steps listed in claim
 1. 6. The method of claim 1, whereby those sections of said volatile memory (14) which contain the objects (A, B, C, D, E, F, G) which have no positive reachability information (VF), are reclaimed.
 7. The method of claim 6, whereby said volatile memory (14) is compacted by rearranging those sections of said volatile memory (14) that are reclaimed.
 8. The method of claim 1, wherein the reachability information (VF) is aligned in parallel to the objects (A, B, C, D, E, F, G) and where preferably the objects (A, B, C, D, E, F, G) are aligned at object addresses (aA, aB, aC, aD, aE, aF, aG) which are a multiple of a number n.
 9. Computer program product comprising program code means for performing a method according to one of the preceding claims.
 10. Computer program product according to claim 9, comprising the program code means stored on a computer-readable medium.
 11. Apparatus for distinguishing reachable objects (A, B, C, E) and non-reachable objects (D, F, G) in an object-based application, comprising a volatile memory (14) and a non-volatile memory (13), said object-based application operating in said non-volatile memory (13) on said objects (A, B, C, D, E, F, G), whereof at least one is a root object (A), said apparatus further comprising: a processor (12) for processing each root object (A) by writing for each object (A, B, C, D, E, F, G) that is reachable from said root object (A), a positive reachability information (VF) into said volatile memory (14), and marking those objects (A, B, C, D, E, F, G) in said non-volatile memory (13) as reusable memory, for which no positive reachability information (VF) is present in said volatile memory (14).
 12. The apparatus of claim 11, further comprising means for identifying an object (A, B, C, D, E, F, G) which has not been marked because its path (TO) from said root object (A) does not fit into said volatile memory (14), as an object (A, B, C, D, E, F, G) which has to be processed later, preferably as an additional root object.
 13. The apparatus of claim 11 or 12, further comprising a counter for counting the number (Z) of root objects that were not yet processed, said number (Z) being preferably stored in said volatile memory (14).
 14. The apparatus of one of claims 11 to 13, further comprising a reclaimer means for reclaiming those sections of said volatile memory (14) which contain the objects (A, B, C, D, E, F, G) which have no positive reachability information (VF).
 15. The apparatus one of claims 11 to 14, further comprising a defragmenter for compacting said volatile memory 14 by rearranging those sections of said volatile memory (14) which contain the objects (A, B, C, D, E, F, G) which have no positive reachability information (VF).
 16. The apparatus of one of claims 11 to 15, wherein said objects (A, B, C, D, E, F, G) are kept in the non-volatile memory
 13. 17. The apparatus of one of claims 11 to 16 being part of a system with constrained resources, preferably an integrated-circuit card (10). 